package com.sailing.core.java.lang;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringTest {
	public static final String OMEGAREGX = "http(s)?://www\\.omegatravel\\.net/\\?page/id/[\\d]{1,9}";
	public static final String LLXREGX = "lulutrip";

	public static String replace(String source, String oldStr, String newStr,
			boolean matchCase) {
		if (source == null) {
			return null;
		}
		if (source.toLowerCase().indexOf(oldStr.toLowerCase()) == -1) {
			return source;
		}
		int findStartPos = 0;
		int a = 0;
		while (a > -1) {
			int b = 0;
			String str1, str2, str3, str4, strA, strB;
			str1 = source;
			str2 = str1.toLowerCase();
			str3 = oldStr;
			str4 = str3.toLowerCase();
			if (matchCase) {
				strA = str1;
				strB = str3;
			} else {
				strA = str2;
				strB = str4;
			}
			a = strA.indexOf(strB, findStartPos);
			if (a > -1) {
				b = oldStr.length();
				findStartPos = a + b;
				StringBuffer bbuf = new StringBuffer(source);
				source = bbuf.replace(a, a + b, newStr) + "";
				findStartPos = findStartPos + newStr.length() - b;
			}
		}
		return source;
	}

	public static String replaceWithRE(String routeStrand, String[] allReg) {
		if (allReg == null || allReg.length == 0) {
			return "";
		}
		for (String reg : allReg) {

			Pattern pt = Pattern.compile(reg);
			Matcher mt = pt.matcher(routeStrand);
			if (mt.find()) {
				String s = mt.group();
				System.out.println("s is : " + s);
				routeStrand = replace(routeStrand, s, "", true);
			}
		}
		return routeStrand;
	}

	public static void main(String[] args) {
		String vendorName = "Lulutrip";
		boolean equRest = vendorName.equalsIgnoreCase("lulutrip");
		System.out.println(equRest);

		String llxstr = "Lulutrip将无法为您lulutrip提供接送机服务Lulutrip";
		String matchResult = StringTest.replaceWithRE(llxstr, new String[] {
				"lulutrip", "Lulutrip" });
		System.out.println(matchResult);
	}
}
